package com.niit.activity.service;

import com.niit.activity.entity.Topic;
import com.niit.activity.mapper.TopicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TopicService {
    @Autowired
    private TopicMapper topicMapper;

    public void addTopic(Topic topic) {
        topicMapper.addTopic(topic);
    }

    public List<Topic> getAllTopics() {
        return topicMapper.getAllTopics();
    }

    public Topic getTopicById(Long topicId) {
        return topicMapper.getTopicById(topicId);
    }

    public String getTopicContentById(Long topicId) {
        return topicMapper.getTopicContentById(topicId);
    }

    /**
     * 更新话题的计数器（如点赞数、评论数等）
     *
     * @param topicId 话题唯一标识符
     */
    public void updateTopicNum(Long topicId) {
        if (topicId == null || topicId <= 0) {
            throw new IllegalArgumentException("topicId 必须为正整数");
        }
        topicMapper.updateTopicNum(topicId);
    }
    /**
     * 减少话题的计数器
     *
     * @param topicId 话题唯一标识符
     */
    public void decreaseTopicNum(Long topicId) {
        if (topicId == null || topicId <= 0) {
            throw new IllegalArgumentException("topicId 必须为正整数");
        }
        topicMapper.decreaseTopicNum(topicId);
    }
}